package exam.business.service;

import java.util.List;

import exam.common.constant.ResultPort;
import exam.common.key.KeyQuestion;
import exam.common.util.ConvertUtils;
import exam.common.util.NullCheckUtil;
import exam.model.dao.TAnswerDAO;
import exam.model.dao.TQuestionDAO;
import exam.model.entity.TAnswerEntity;
import exam.model.entity.TQuestionEntity;
import exam.system.business.AbstractService;
import exam.system.business.BusinessServiceInfo;
/**
 * <p>QuestionGetService</p>
 * <br>
 * <p>Xu lay thong tin cau hoi</p>
 * 
 * @author Phong
 * @version 21/5/2012
 */
public class QuestionGetService extends AbstractService {
	// tQuestionDAO
	private TQuestionDAO tQuestionDAO = new TQuestionDAO();
	// tAnswerDAO
	private TAnswerDAO tAnswerDAO = new TAnswerDAO();
	@Override
	public String executeService(BusinessServiceInfo serviceInfo)
			throws Exception {
		// lay questionId tu serviceInfo
		String questionId = serviceInfo.getString(KeyQuestion.QUESTION_ID);
		// goi method lay thong tin cau hoi
		TQuestionEntity tQuestionEntity = tQuestionDAO
				.selectByPk(ConvertUtils.convertStringToLong(questionId));
		if(NullCheckUtil.isNull(tQuestionEntity)) {
			return ResultPort.NONE;
		}
		// goi method lay danh sach dap an
		List<TAnswerEntity> tAnswerEntityList = tAnswerDAO
				.selectByQuestionId(tQuestionEntity.getQuestionId());
		// put thong tin cau hoi vao serviceInfo
		serviceInfo.put(KeyQuestion.T_QUESTION_ENTITY, tQuestionEntity);
		// put danh sach dap an vao serviceInfo
		serviceInfo.put(KeyQuestion.T_ANSWER_ENTITY_LIST, tAnswerEntityList);
		return ResultPort.SUCCESS;
	}

}
